<template>
    <!-- 滑块弹窗 -->
    <f7-popup class="terminate-popup-swipe" @popup:closed="fClose" :opened="opendStatus">
        <f7-page>
            <f7-navbar>
                <f7-nav-left>
                    <f7-link popup-close> <i class="nav-icon__back f7-icons">chevron_left</i> </f7-link>
                </f7-nav-left>
                <f7-nav-title>终止</f7-nav-title>
            </f7-navbar>

            <qm-form ref="form">
                <qm-field
                    label="意见"
                    type="textarea"
                    rows="5"
                    placeholder="请填写你的终止意见"
                    :value="workflowComment"
                    @input="workflowComment = $event"
                ></qm-field>
                <qm-button title="终止" type="primary" fill @click="fuSubmit"></qm-button>
            </qm-form>
        </f7-page>
    </f7-popup>
</template>

<script>
export default {
    name: "QmWorkflowTerminate",
    props: {
        terminate: String,
    },
    data() {
        return {
            opendStatus: false,
            workflowComment: ""
        }
    },
    methods: {
        fClose() {
            this.opendStatus = false;
        },
        fuSubmit() {
            this.$f7.dialog.confirm("确定要终止吗", confirm=> {
                if (this.terminate) {
                    this.$f7.preloader.show();
                    this.$util.request(
                        this.terminate,
                        {
                            workflowComment: this.workflowComment
                        },
                        "post"
                    ).then(res=> {
                        this.$f7.preloader.hide();
                        if (res.data.success) {
                            this.$f7.popup.close(".terminate-popup-swipe");
                            this.$f7.dialog.alert("终止成功", ()=>{
                                this.$f7.views.current.router.back();
                            })
                        } else {
                            this.$f7.dialog.alert("终止失败");
                        }
                    }).catch(err=> {
                        this.$f7.preloader.hide();
                        this.$f7.dialog.alert("终止失败");
                        throw err;
                    })
                }
            })
        }
    }
}
</script>

<style>
</style>